Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2ccUtil = require("ccUtil");
function i() {}
var s = Object.create(null);
var def_gameSyncIfy = {
  playAnim(e, t, n) {
    n = Object.assign({}, n);
    var _ref2 = n || s;
    var _ref2$complete = _ref2.complete;
    var o = _ref2$complete === undefined ? i : _ref2$complete;
    var _ref2$fail = _ref2.fail;
    var a = _ref2$fail === undefined ? i : _ref2$fail;
    var _ref2$onecomplete = _ref2.onecomplete;
    var r = _ref2$onecomplete === undefined ? i : _ref2$onecomplete;
    e.active = Boolean(t);
    if (e) {
      var _i39 = e.getComponent(cc.Animation);
      if (_i39) {
        n.reset && _i39.setCurrentTime(0);
        _i39.on(cc.Animation.EventType.LASTFRAME, r, null);
        _i39.once(cc.Animation.EventType.FINISHED, o, null);
        _i39.play(t);
      } else {
        cc.log("[警告] 节点不存在animation组件");
        a();
      }
    } else {
      cc.log("[警告] 播放animation动画时node为空");
      a();
    }
  },
  playAnimSync(e, t) {
    var _this174 = this;
    return new Promise(function (n, o) {
      var i = {
        complete: n,
        fail: o
      };
      _this174.playAnim(e, t, i);
    });
  },
  playSpine(e, t, n) {
    var _ref3 = n || s;
    var _ref3$timeScale = _ref3.timeScale;
    var o = _ref3$timeScale === undefined ? 1 : _ref3$timeScale;
    var _ref3$complete = _ref3.complete;
    var a = _ref3$complete === undefined ? i : _ref3$complete;
    var _ref3$fail = _ref3.fail;
    var r = _ref3$fail === undefined ? i : _ref3$fail;
    var _ref3$action = _ref3.action;
    var l = _ref3$action === undefined ? i : _ref3$action;
    var _ref3$count = _ref3.count;
    var c = _ref3$count === undefined ? 1 : _ref3$count;
    if (e) {
      e.active = true;
      var _n86 = e.getComponent(sp.Skeleton);
      if (_n86) {
        c <= 0 && (_n86._oldAnimalName = t);
        _n86.setEventListener(function (e, t) {
          l(e, t);
        });
        _n86.timeScale = o;
        _n86.setCompleteListener(a);
        if (t) {
          _n86.setAnimation(0, t, 1 != c);
        } else {
          _n86.clearTracks();
        }
      } else {
        cc.log("[警告] 播放spine动画时Skeleton为空");
        r();
      }
    } else {
      cc.log("[警告] 播放spine动画时node为空");
      r();
    }
  },
  restoreSpine(e) {
    var t = e.getComponent(sp.Skeleton);
    t._oldAnimalName && this.playSpine(e, t._oldAnimalName, {
      count: 0
    });
  },
  playSpineSync(e, t, n) {
    var _this175 = this;
    return new Promise(function (o, i) {
      n = Object.assign({
        complete: o,
        fail: i
      }, n);
      _this175.playSpine(e, t, n);
    });
  },
  delay(e) {
    var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : .5;
    var n = arguments.length > 2 ? arguments[2] : undefined;
    var _ref4 = n || s;
    var _ref4$complete = _ref4.complete;
    var o = _ref4$complete === undefined ? i : _ref4$complete;
    var _ref4$fail = _ref4.fail;
    var a = _ref4$fail === undefined ? i : _ref4$fail;
    e.scheduleOnce(function () {
      o();
    }, t);
  },
  delaySync(e) {
    var _this176 = this;
    var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : .5;
    return new Promise(function (n, o) {
      var i = {
        complete: n,
        fail: o
      };
      _this176.delay(e, t, i);
    });
  },
  simpleTweenSync(e, t, n) {
    return new Promise(function (o) {
      cc.tween(e).to(t, n).call(function () {
        o(null);
      }).start();
    });
  },
  simpleTweenBySync(e, t, n) {
    return new Promise(function (o) {
      cc.tween(e).by(t, n).call(function () {
        o(null);
      }).start();
    });
  },
  wait(e) {
    return new Promise(function (t) {
      setTimeout(t, 1e3 * e);
    });
  },
  getChild(e, t) {
    if (e) {
      var _n87 = e.split("/");
      for (var _o158 = 0; _o158 < _n87.length - 1; _o158++) {
        t = t.getChildByName(_n87[_o158]);
        if (!t) {
          cc.log("查找子节点,路径".concat(e, "错了"));
        }
      }
      if (t) {
        return t.getChildByName(_n87[_n87.length - 1]);
      }
      cc.log("找不到子节点:".concat(e));
    } else {
      cc.log("传入的name不能为空");
    }
  },
  onlyShowChild(e, t) {
    var n = def_gameSyncIfy.getChild(e, t);
    if (n) {
      var _e95 = n.getComponent(cc.Sprite);
      _e95 && (_e95.enabled = false);
      def_gameSyncIfy.setChildrenViseble(n, true);
    }
  },
  getChilds(e, t) {
    var n = e.split("|");
    var o = [];
    for (var _i40 = 0; _i40 < n.length; _i40++) {
      o[_i40] = def_gameSyncIfy.getChild(n[_i40], t);
    }
    return o;
  },
  setChildrenViseble(e) {
    var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
    $2ccUtil.default.setChildrenViseble(e, t);
  },
  showSubSprite(e) {
    var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
    var n = e.getComponent(cc.Sprite);
    if (n) {
      if (t) {
        n.enabled = false;
        $2ccUtil.default.setChildrenViseble(e, true);
      } else {
        n.enabled = true;
        $2ccUtil.default.setChildrenViseble(e, false);
      }
    }
  },
  hideSlot(e, t) {
    if (e) {
      var _n88 = e.getComponent(sp.Skeleton).findSlot(t);
      _n88 && (_n88.color.a = 0);
    }
  },
  showSlot(e, t) {
    if (e) {
      var _n89 = e.getComponent(sp.Skeleton).findSlot(t);
      _n89 && (_n89.color.a = 1);
    }
  },
  parseAction(e) {
    var t = e.trim().split("\n");
    var n = [];
    for (var _o159 = 0; _o159 < t.length; _o159++) {
      var _e96 = t[_o159].trim().split(",");
      for (var _t85 = 0; _t85 < _e96.length; _t85++) {
        var _o160 = {
          action: "",
          value: null
        };
        n.push(_o160);
        var _i41 = _e96[_t85].split("&");
        for (var _e97 = 0; _e97 < _i41.length; _e97++) {
          var _t86 = _i41[_e97].split("=");
          var _n90 = _t86[0].trim();
          var _s18 = _t86[1].trim();
          if (0 == _e97) {
            _o160.action = _n90;
            _o160.value = _s18;
          } else {
            _o160[_n90] = _s18;
          }
        }
      }
    }
    return n;
  }
};
exports.default = def_gameSyncIfy;